<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="com.app.service.vo.RoleVo"%>
<%@ page import="com.app.service.vo.CornCompetenceVo"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'main-role.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<script type="text/javascript" src="../js/jquery-1.7.2.js"></script>
<script type="text/javascript">
	   function showcompetence(divid,ruleid,rulename)
	   {
	   		var v = document.getElementById(divid).style.display;
	   		if(v=="")
	   		{
	   		document.getElementById(divid).style.display = "none";
	   		}else
	   		{
	   							
	   			document.getElementById(divid).style.display="";
	   			document.getElementById("showruleid").innerHTML="<b>"+rulename+"</b>";
	   			document.getElementById("ruleid").value=ruleid;
	   			var checkeds = document
									.getElementsByName("compenteid");
				for(var i=0;i<checkeds.length;i++)
				{	
					checkeds[i].checked=false;	
				}
	   				$.ajax({
			url : "<%=request.getContextPath()%>/ajax.form",
						type : 'POST',
						data : "ruleid=" + ruleid + "&key=r-c-checked",
						dataType : 'json',
						async : false,
						contentType : "application/x-www-form-urlencoded; charset=utf-8",
						timeout : 3000,
						error : function(XMLHttpRequest, textStatus,
								errorThrown) {

							alert('Error ' + XMLHttpRequest + textStatus
									+ errorThrown);
						},
						success : function(result) {
							var arg = result["checkeds"];
							
							for ( var i = 0; i < arg.length; i++) {

								for ( var j = 0; j < checkeds.length; j++) {

									if (arg[i] == checkeds[j].value) {
										checkeds[j].checked=true;

									}
								}
							}
						}
					});

		}

	}
</script>
</head>

<body>
	<table width="95%">
		<tr>
			<td>角色名</td>
			<td>角色描述</td>
			<td>绑定</td>
		</tr>
		<%
			List<RoleVo> list = (List<RoleVo>) request
					.getAttribute("rule-list");
			for (RoleVo vo : list) {
		%>
		<tr>
			<td><%=vo.getName()%></td>
			<td><%=vo.getRolesDescription()%></td>
			<td><a
				href="javaScript:showcompetence('competenceid','<%=vo.getId()%>','<%=vo.getName()%>')">绑定权限</a>
			</td>
		</tr>

		<%
			}
		%>
	</table>
	<hr>
	<div id="competenceid" style="display:none">
		<form action="<%=request.getContextPath()%>/rule/banging.form"
			method="post">
			<span id="showruleid"></span>
			<table width="95%">
				<tr>
					<td>权限名</td>
					<td>权限描述</td>
					<td>权限绑定</td>

				</tr>
				<%
					List<CornCompetenceVo> volist = (List<CornCompetenceVo>) request
							.getAttribute("competence-list");
					for (CornCompetenceVo vo : volist) {
				%>
				<tr>
					<td><%=vo.getName()%></td>
					<td><%=vo.getCompetenceDescription()%></td>
					<td>选定：<input type="checkbox" name="compenteid" 
						value="<%=vo.getId()%>" />
						
					</td>
				</tr>

				<%
					}
				%>
			</table>
			<input type="hidden" id="ruleid" name="ruleid" /> <input 
				type="submit" value="角色绑定权限" />
		</form>
	</div>
</body>
</html>
